package com.devfans.changeskin;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import skin.support.SkinCompatManager;

public class MainActivity extends BaseActivity implements View.OnClickListener {

    private Button btnChangeRedSkin;
    private Button btnChangeBlackSkin;
    private Button btnRestoreSkin;
    private Context mContext;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = this;
        setContentView(R.layout.activity_main);
        initView();
        initListener();
    }

    private void initView() {
        btnRestoreSkin = (Button) findViewById(R.id.btn_restoreSkin);
        btnChangeRedSkin = (Button) findViewById(R.id.btn_red_skin);
        btnChangeBlackSkin = (Button) findViewById(R.id.btn_black_skin);
    }

    private void initListener() {
        btnRestoreSkin.setOnClickListener(this);
        btnChangeRedSkin.setOnClickListener(this);
        btnChangeBlackSkin.setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId())
        {
            case R.id.btn_red_skin:
                redSkin();
                break;
            case R.id.btn_black_skin:
                blackSkin();
                break;
            case R.id.btn_restoreSkin:
                restoreSkin();
                break;
        }
    }

    /*private void loadSkin(){
        // 指定皮肤插件
        SkinCompatManager.getInstance().loadSkin("black.skin", new SkinCompatManager.SkinLoaderListener() {
            @Override
            public void onStart() {
                //Toast.makeText(mContext,"开始设置皮肤",Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onSuccess() {
                //Toast.makeText(mContext,"皮肤设置成功",Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onFailed(String errMsg) {
                //Toast.makeText(mContext,"皮肤设置失败",Toast.LENGTH_SHORT).show();
            }
        });
    }*/

    private void redSkin(){
        //SkinFileUtils.getSkinDir(this);
        // 指定皮肤插件
        SkinCompatManager.getInstance().loadSkin("red.skin", new SkinCompatManager.SkinLoaderListener() {
            @Override
            public void onStart() {
                //Toast.makeText(mContext,"开始设置皮肤",Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onSuccess() {
                //Toast.makeText(mContext,"皮肤设置成功",Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onFailed(String errMsg) {
                //Toast.makeText(mContext,"皮肤设置失败",Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void blackSkin(){
        //SkinFileUtils.getSkinDir(this);
        // 指定皮肤插件
        SkinCompatManager.getInstance().loadSkin("black.skin", new SkinCompatManager.SkinLoaderListener() {
            @Override
            public void onStart() {
                //Toast.makeText(mContext,"开始设置皮肤",Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onSuccess() {
                //Toast.makeText(mContext,"皮肤设置成功",Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onFailed(String errMsg) {
                //Toast.makeText(mContext,"皮肤设置失败",Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void restoreSkin(){
        // 恢复应用默认皮肤
        SkinCompatManager.getInstance().restoreDefaultTheme();
    }
}
